package com.atguigu.lease.web.admin.service.impl;

import com.atguigu.lease.model.entity.*;
import com.atguigu.lease.web.admin.mapper.*;
import com.atguigu.lease.web.admin.service.LeaseAgreementService;
import com.atguigu.lease.web.admin.vo.agreement.AgreementQueryVo;
import com.atguigu.lease.web.admin.vo.agreement.AgreementVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import jakarta.annotation.Resource;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

/**
 * @author liubo
 * @description 针对表【lease_agreement(租约信息表)】的数据库操作Service实现
 * @createDate 2023-07-24 15:48:00
 */
@Service
public class LeaseAgreementServiceImpl extends ServiceImpl<LeaseAgreementMapper, LeaseAgreement>
        implements LeaseAgreementService {
    @Resource
    private ApartmentInfoMapper apartmentInfoMapper;
    @Resource
    private RoomInfoMapper roomInfoMapper;
    @Resource
    private PaymentTypeMapper paymentTypeMapper;
    @Resource
    private LeaseTermMapper leaseTermMapper;
    @Resource
    private LeaseAgreementMapper leaseAgreementMapper;


    //根据id查询租约信息
    @Override
    public AgreementVo getByAgreementVoId(Long id) {
        //1.查询租约信息表当中的信息 获取到签约公寓的id 签约房间的id
        //支付方式的id，以及租期的id
        LeaseAgreement leaseAgreement = super.getById(id);
        //2.根据id查询名下签约的公寓信息
        ApartmentInfo apartmentInfo = apartmentInfoMapper.selectById(leaseAgreement.getApartmentId());
        //3.根据id查询名下签约房间信息
        RoomInfo roomInfo = roomInfoMapper.selectById(leaseAgreement.getRoomId());
        //4.根据id查询名下的支付方式信息
        PaymentType paymentType = paymentTypeMapper.selectById(leaseAgreement.getPaymentTypeId());
        //5.根据id查询名下的租期信息
        LeaseTerm leaseTerm = leaseTermMapper.selectById(leaseAgreement.getLeaseTermId());
        //6.将查询到的内容信息组装成Vo的实体信息
        AgreementVo agreementVo = new AgreementVo();
        //6.1利用BeanUtils当中的copyProperties方法将leaseAgreement当中的信息拷贝到agreementVo当中
        BeanUtils.copyProperties(leaseAgreement,agreementVo);
        //6.2封装以下的四个实体内容信息
        agreementVo.setApartmentInfo(apartmentInfo);
        agreementVo.setLeaseTerm(leaseTerm);
        agreementVo.setRoomInfo(roomInfo);
        agreementVo.setPaymentType(paymentType);
        //7.将封装好的实体信息进行返回
        return agreementVo;
    }

    //根据条件分页查询租约列表
    @Override
    public IPage<AgreementVo> pageAgreement(Page<AgreementVo> page, AgreementQueryVo queryVo) {
        return leaseAgreementMapper.pageAgreement(page,queryVo);
    }
    //根据条件分页查询租约信息




}




